Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix two warnings (possible bugs) #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

stevengj
Copy link

@stevengj stevengj commented Apr 9, 2020

This PR fixes two compiler warnings, which may indicate bugs:

Fixes warning:

    ReadGDSIIFile.cc:622:19: warning: cast from 'libGDSII::BYTE *' (aka 'unsigned char *') to
          'libGDSII::WORD *' (aka 'unsigned short *') increases required alignment from 1 to 2
          [-Wcast-align]
            WORD W = *(WORD *)Payload;

Rather than perform a pointer cast, just explicitly load two bytes and shift them to make a 16-bit word. This has the additional advantage of being more portable, because we can specify the endian-ness with which we read the data. ( I used a little-endian order for backward compatibility with x86 machines. It's not clear to me whether the GDSII format specifies a particular interpretation of bitfield indices, so that endianness matters here?)

Also fix warning:

    ReadGDSIIFile.cc:654:50: warning: adding 'libGDSII::BYTE' (aka 'unsigned char') to a
          string does not append to the string [-Wstring-plus-int]
           *ErrMsg = new string("unknown data type " + DType);
                                ~~~~~~~~~~~~~~~~~~~~~^~~~~~~
    ReadGDSIIFile.cc:654:50: note: use array indexing to silence this warning
           *ErrMsg = new string("unknown data type " + DType);

The std::string + char method does not apply to string literals, which are just pointers. Instead, I just leave a placeholder character X in the string and overwrite it with DType.

stevengj added 2 commits April 9, 2020 08:14
ReadGDSIIFile.cc:622:19: warning: cast from 'libGDSII::BYTE *' (aka 'unsigned char *') to
      'libGDSII::WORD *' (aka 'unsigned short *') increases required alignment from 1 to 2
      [-Wcast-align]
        WORD W = *(WORD *)Payload;

Rather than perform a pointer cast, just explicitly load two bytes and shift them
to make a 16-bit word.   This has the additional advantage of being more portable,
because we can specify the endian-ness with which we read the data.

I used a little-endian order for backward compatibility with x86 machines.
(It's not clear to me whether the GDSII format specifies a particular
interpretation of bitfield indices, so that endianness matters here?)
ReadGDSIIFile.cc:654:50: warning: adding 'libGDSII::BYTE' (aka 'unsigned char') to a
      string does not append to the string [-Wstring-plus-int]
       *ErrMsg = new string("unknown data type " + DType);
                            ~~~~~~~~~~~~~~~~~~~~~^~~~~~~
ReadGDSIIFile.cc:654:50: note: use array indexing to silence this warning
       *ErrMsg = new string("unknown data type " + DType);

The std::string + char method does not apply to string literals, which are just
just pointers.   Instead, just leave a placeholder character X in the string
and overwrite it with DType.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant